package com.tsj.mvp.demo3;

import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import com.tsj.mvp.R;

/**
 * 该demo3为优化loginPresenter,添加绑定和解绑
 * 不足，每个presenter都需要attach和detach，不方便，所以demo4将attach和detach封装到basePresenter
 * */
public class MainActivity3 extends AppCompatActivity implements LoginView3 {

    private LoginPresenter3 loginPresenter3;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    public void onClickView(View view){
        loginPresenter3 = new LoginPresenter3();
        loginPresenter3.attachView(this);
        loginPresenter3.login("123456","123456");
    }

    @Override
    public void onLoginResult(String result) {
        Toast.makeText(this,result,Toast.LENGTH_LONG).show();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if(loginPresenter3 != null){
            loginPresenter3.detachView();
        }
    }
}